-- 测试

local HumanBone = TaleWorlds.Core.HumanBone
local MatrixFrame = TaleWorlds.Library.MatrixFrame
local Debug = TaleWorlds.Library.Debug
local Input = TaleWorlds.InputSystem.Input
local InputKey = TaleWorlds.InputSystem.InputKey
local Agent = TaleWorlds.MountAndBlade.Agent
local ParticleSystem = TaleWorlds.Engine.ParticleSystem
local ParticleSystemManager = TaleWorlds.Engine.ParticleSystemManager
local SoundManager = TaleWorlds.Engine.SoundManager
local SoundEvent = TaleWorlds.Engine.SoundEvent
local SkinVoiceManager = TaleWorlds.MountAndBlade.SkinVoiceManager

local pid = 1
local pss = { --都是只播一次的粒子
    -- general
    "dust_fall_a",
    -- basic
    "prt_hit_dust",
    -- hardcarded_misc1
    "psys_burning_projectile_default_coll",
    "psys_burning_projectile_stone_coll",
    "psys_burning_projectile_water_coll",
    "psys_burning_projectile_wood_coll",
    "psys_burning_woods_parts",
    "psys_campaign_ballista_destruction",
    "psys_campaign_boulder_stone_coll",
    "psys_dummy_smoke",
    "psys_dummy_straw",
    "psys_game_ballista_destruction",
    "psys_game_ballista_water_coll",
    "psys_game_ballista_weapon_destroy",
    "psys_game_ballistamissile_default_coll",
    "psys_game_ballistamissile_grass_coll",
    "psys_game_ballistamissile_metal_coll",
    "psys_game_ballistamissile_mud_coll",
    "psys_game_ballistamissile_stone_coll",
    "psys_game_ballistamissile_wood_coll",
    "psys_game_batteringram_door_hit",
    "psys_game_blood_1",
    "psys_game_blood_4",
    "psys_game_blood_sword_enter",
    "psys_game_blood_sword_exit",
    "psys_game_water_splash_1",
    "psys_game_wood_dust_a",
    "psys_game_wood_splinter_a",
    "psys_game_wooden_merlon_destruction",
    "psys_ladder_dust_10m",
    "psys_mapicon_boulder_stone_coll",
    "psys_siege_door_falling_dust",
    "psys_smoke",
    -- hardcarded_misc2
    "psys_game_boulder_default_coll",
    "psys_game_boulder_mud_coll",
    "psys_game_boulder_wood_coll",
    "psys_game_broken_arrow",
    "psys_game_hoof_default_col",
    "psys_game_hoof_dust_2",
    "psys_game_hoof_dust_mud",
    "psys_game_hoof_dust_on_stone",
    "psys_game_hoof_grass_col",
    "psys_game_hoof_mud_col",
    "psys_game_hoof_stone_col",
    "psys_game_hoof_water_coll",
    "psys_game_infantry_default_col",
    "psys_game_infantry_grass_col",
    "psys_game_infantry_mud_col",
    "psys_game_infantry_stone_col",
    "psys_game_merlon_aserai_l3",
    "psys_game_metal_metal_coll",
    "psys_game_metal_stone_coll",
    "psys_game_metal_wood_coll",
    "psys_game_missile_default_coll",
    "psys_game_missile_metal_coll",
    "psys_game_missile_mud_coll",
    "psys_game_missile_sand_coll",
    "psys_game_missile_stone_coll",
    "psys_game_missile_water_coll",
    "psys_game_missile_wood_coll",
    "psys_game_shield_break",
    "psys_game_sparkle_a",
    "psys_game_stone_default_coll",
    "psys_game_stone_dust_a",
    "psys_game_stone_gravel",
    "psys_game_stone_stone_coll",
    "psys_game_stone_water_coll",
    "psys_game_stone_wood_coll",
}

local sid = 1
local ses = {

}

return {
    load = function ()
        InformationManager.DisplayMessage(InformationMessage("lua 测试文本"))
    end,
    tick = function (dt)
        local player = Agent.Main
        if player == nil then
            return
        end

        if Input.IsKeyPressed(InputKey.D1) then
            InformationManager.DisplayMessage(InformationMessage("玩家"..player.Name))
            -- local visuals = player.AgentVisuals
            -- local boneIndex = visuals:GetRealBoneIndex(HumanBone.Neck)
            -- local _, boneLocalParticleFrame = visuals:CreateParticleSystemAttachedToBone("dust_fall_a", boneIndex, MatrixFrame.Identity)

            -- msg = InformationMessage("boneLocalParticleFrame-"..tostring(boneLocalParticleFrame))
            -- InformationManager.DisplayMessage(msg)

        elseif Input.IsKeyPressed(InputKey.D2) then
            SubModule:CreateParticleSystemAttachedToBone(player.AgentVisuals, pss[pid], HumanBone.Neck)
            InformationManager.DisplayMessage(InformationMessage("ps="..pss[pid]))

        elseif Input.IsKeyPressed(InputKey.D3) then
            if Input.IsKeyDown(InputKey.LeftControl) then
                pid = pid - 10
            else
                pid = pid - 1
            end
            if pid < 1 then
                pid = #pss
            end
            InformationManager.DisplayMessage(InformationMessage("pid="..tostring(pid)))
            InformationManager.DisplayMessage(InformationMessage("ps="..pss[pid]))

        elseif Input.IsKeyPressed(InputKey.D4) then
            if Input.IsKeyDown(InputKey.LeftControl) then
                pid = pid + 10
            else
                pid = pid + 1
            end
            if pid > #pss then
                pid = 1
            end
            InformationManager.DisplayMessage(InformationMessage("pid="..tostring(pid)))
            InformationManager.DisplayMessage(InformationMessage("ps="..pss[pid]))
            
        end
    end
}